<!--
 * @Author: Allen
 * @Date: 2021-01-07 14:10:18
 * @Description: 抱怨身处黑暗，不如提灯前行。愿你在自己存在的地方，成为一束光，照亮世界的一角
 * @LastEditTime: 2021-01-15 11:09:41
 * @LastEditors: Allen
 * @FilePath: \WMS\src\views\WMS\baseData\packagStyleManage\edit.vue
 * @Additional: 包装样式弹框
-->
<template>
  <section class="editCarBrand">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="400px"
      @close="sendCode"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :styleType="$store.state.app.dialogType"
      ></dialogHeader>
      <div class="filter-container filter-params">
        <el-row :gutter="26">
          <component
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :validrule="comp.validrule"
            :key="comp.compKey"
            :codeField="comp.codeField"
            :textField="comp.textField"
            :popupsKey="comp.compKey"
            :is="comp.component"
            :code="formField[comp.codeField]"
            :text="formField[comp.textField]"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
            :disabled="comp.disabled"
            :isRequire="comp.isRequire"
            :span="comp.span || 8"
            :isMul="comp.isMul"
            :labelName="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :dateOptionsType="comp.dateOptionsType"
            :isCallBack="comp.isCallBack"
            :isInput="comp.isInput"
            :dataToObject="comp.dataToObject"
          ></component>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from "@/components/wms/mixins/formMixins";
import { basedataApi } from "@/api/wms/basedata";
import requesta from "../../../../utils/request.js";
import storage from "@/utils/storage";
export default {
  // 组件混入对象
  mixins: [formMixins],
  components: {
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  data() {
    return {
      // 保存API配置对象
      apiConfig: basedataApi.savepartmaterials,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.save(),
          text: "保存" //"保存"
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          clickEvent: () => this.reset(),
          text: "重置" //"重置"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "edit_compKey2",
          labelName: "备件编号",
          span: 23,
          codeField: "PART_CODE",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isRequire: true
        },
        {
          compKey: "edit_compKey3",
          labelName: "包材编号",
          span: 23,
          codeField: "MATERIALS_CODE",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isRequire: true
        },
        {
          compKey: "edit_compKey4",
          labelName: "每M个备件",
          span: 23,
          codeField: "PART_NUM",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isInput: true,
          changed: val => {
            if (!val) {
              return;
            }
            this.$refs["trueedit_compKey4"][0].modelCode = (
              this.formField.PART_NUM + ""
            )
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
            this.formField.PART_NUM = (this.formField.PART_NUM + "")
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
          },
          dataToObject: {
            maxLength: 10
          },
          isRequire: true
        },
        {
          compKey: "edit_compKey5",
          labelName: "包材品种需求N",
          span: 23,
          codeField: "MATERIALS_NUM",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isInput: true,
          changed: val => {
            if (!val) {
              return;
            }
            this.$refs["trueedit_compKey5"][0].modelCode = (
              this.formField.MATERIALS_NUM + ""
            )
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
            this.formField.MATERIALS_NUM = (this.formField.MATERIALS_NUM + "")
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
          },
          dataToObject: {
            maxLength: 10
          },
          isRequire: true
        },
        {
          compKey: "edit_compKey7",
          labelName: "启用状态",
          codeField: "IS_ENABLE",
          component: () => import("@/components/wms/isEnable/isEnableOne"),
          type: "dropdownList",
          span: 23,
          isMust: true,
          isRequire: true
        }
      ],
      // 标题
      textMap: {
        edit: "编辑包装样式管理",
        add: "新增包装样式管理"
      },
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        PART_CODE: "",
        MATERIALS_CODE: "",
        PART_NUM: "",
        MATERIALS_NUM: "",
        IS_ENABLE: "1",
        MATERIALS_PART_ID: ""
      },
      WAREHOUSE_USER: []
    };
  },
  methods: {
    //保存
    save() {
      this.$utils.validataMoth(this, "validpopup");
      if (this.valid) {
        var saveObj = JSON.parse(JSON.stringify(this.formField));
        //保存表单
        this.saveForm(saveObj);
        storage.remove(this.$route.query.pageCode);
      }
    }
  }
};
</script>
<style type="text/css" scoped>
.filter-params .el-col label .curName {
  width: 150px;
}
</style>
